<!--#include file="lib/utf-8.asp"-->
<!--#include file="lib/connopen.asp"-->
<!--#include file="lib/asp-common-lib.asp"-->
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>CC的办公系统</title>
<!--#include file="lib/plugins.asp"-->
<style type="text/css">
	.ui-datepicker table {
		border: 0;
	}
	.yform label{
		display:inline;
	}
</style>
<script type="text/javascript">
	$(function() {
		$("#choice").change(function(){
			$("#tele_dept,#tele_empe").prop("disabled",true);
			$("#"+$(this).val()).prop("disabled",false);
		});
		$("#form1").validationEngine();
	});
</script>
<!--#include file="lib/js-google-analytics.asp"-->
</head>
<%
if not CheckPostFlag(session("aaPostFlag"),2,15) then call JumpErrorPage(2)
submit=request.form("submit")
If submit<>"" Then
	conn.BeginTrans
	tele_id=request.form("tele_id")
	tele_num=request.form("tele_num")
	choice=request.form("choice")
	tele_choice=request.form(choice)
	' tele_dept=request.form("tele_dept")
	' tele_empe=request.form("tele_empe")
	tele_weight=request.form("tele_weight")
	if submit="新增" then
		sql="insert into tele(tele_num,"&choice&",tele_weight) values('"&tele_num&"',"&tele_choice&","&tele_weight&")"
		tele_id=ExecuteCommand(sql,true)
	end if
	if submit="保存" then
		if choice="tele_dept" then sql="update tele set tele_num='"&tele_num&"',"&choice&"="&tele_choice&",tele_empe=Null,tele_weight="&tele_weight&" where tele_id="&tele_id
		if choice="tele_empe" then sql="update tele set tele_num='"&tele_num&"',"&choice&"="&tele_choice&",tele_dept=Null,tele_weight="&tele_weight&" where tele_id="&tele_id
		call ExecuteCommand(sql,false)
	end if
	if err.number=0 then 
		conn.CommitTrans  '如果没有conn错误，则执行事务提交
	else
		conn.RollbackTrans '否则回滚
		'回滚后的其他操作
		'strerr=err.Description
		url=request.ServerVariables("http_host")&request.ServerVariables("url")
		Response.Write "数据库错误！<br /><font color=red>Error # " & CStr(Err.Number) & "<br />" & Err.Description & "<br />Source: " & Err.Source &"<br />错误页面："&url&"</font><br />"
		Response.End
	end if
else
	tele_id=request.querystring("tele_id")
end if

if tele_id<>"" then
	Set rs = Server.CreateObject("ADODB.Recordset")
	sql="select * from tele where tele_id="&tele_id
	rs.Open sql,conn,1,1
	if not rs.eof then
		tele_num=rs("tele_num")
		tele_dept=rs("tele_dept")
		tele_empe=rs("tele_empe")
		if not isnull(tele_dept) then choice="tele_dept"
		if not isnull(tele_empe) then choice="tele_empe"
		tele_weight=rs("tele_weight")
	else
		response.write("没有此号码")
		response.end
	end if
	rs.close
	set rs=nothing
end if
%>
<body>
<!--#include file="lib/header.asp"-->
<!--#include file="lib/nav.asp"-->
<div id="main">
<!--#include file="lib/col1.asp"-->
<!--#include file="lib/col2.asp"-->
	<div id="col3" role="main">
		<div id="col3_content" class="clearfix">
			<form id="form1" name="form1" class="yform" method="post">
					<label for="tele_num">电话号码</label>
					<input id="tele_num" name="tele_num" class="validate[required,custom[onlyNumber],minSize[8],maxSize[8]]" size="8" maxlength="8" value="<%=tele_num%>" />
					<label for="choice">归属</label>
					<select id="choice" name="choice">
						<option disabled="disabled" selected="selected">选择归属</option>
						<option value="tele_dept" <%if choice="tele_dept" then response.write("selected='selected'")%>>部门</option>
						<option value="tele_empe" <%if choice="tele_empe" then response.write("selected='selected'")%>>员工</option>
					</select>
					<select id="tele_dept" name="tele_dept" <%if tele_id="" or choice<>"tele_dept" then response.write("disabled='disabled'")%>>
					<%
						Set rs_dept = Server.CreateObject("ADODB.Recordset")
						sql_dept = "SELECT * FROM dept order by dept_name"
						rs_dept.Open sql_dept,conn,1,1
						do while not rs_dept.eof
					%>
						<option value="<%=rs_dept("dept_id")%>" <%if tele_dept=rs_dept("dept_id") then response.write("selected='selected'")%>><%=rs_dept("dept_name")%></option>
					<%
							rs_dept.movenext
						loop
						rs_dept.close
						set rs_dept=nothing
					%>
					</select>
					<select id="tele_empe" name="tele_empe" <%if tele_id="" or choice<>"tele_empe" then response.write("disabled='disabled'")%>>
					<%
						Set rs_empe = Server.CreateObject("ADODB.Recordset")
						sql_empe = "SELECT * FROM empe order by empe_name"
						rs_empe.Open sql_empe,conn,1,1
						do while not rs_empe.eof
					%>
						<option value="<%=rs_empe("empe_id")%>" <%if tele_empe=rs_empe("empe_id") then response.write("selected='selected'")%>><%=rs_empe("empe_name")%></option>
					<%
							rs_empe.movenext
						loop
						rs_empe.close
						set rs_empe=nothing
					%>
					</select>
					<label for="tele_weight">权重</label>
					<input id="tele_weight" name="tele_weight" value="<%=tele_weight%>" class="validate[required,custom[number],min[0],max[1]]" />
					<input type="hidden" name="tele_id" value="<%=tele_id%>" />
					<input type="submit" name="submit" class="submit" value="保存" />
					<input type="submit" name="submit" class="submit" value="新增" />
					<input name="reset" type="reset" value="重置" />

			</form>		
			<table class="full">
				<thead>
					<tr>
						<th>序号</th>
						<th>电话号码</th>
						<th>员工</th>
						<th>部门</th>
						<th>权重</th>
						<%if CheckPostFlag(session("aaPostFlag"),2,15) then%>
						<th>删除</th>
						<%end if%>
					</tr>
				</thead>
				<tbody>
			<%
				Set rs = Server.CreateObject("ADODB.Recordset")
				sql = "SELECT * FROM tele_all order by dept_index asc,tele_weight asc,tele_num asc"
				rs.Open sql,conn,1,1
				do while not rs.eof

			%>
					<tr>
						<td><%=rs.AbsolutePosition%></td>
						<td><a href="managetele.asp?tele_id=<%=rs("tele_id")%>"><%=rs("tele_num")%></a></td>
						<td><%=rs("empe_name")%></td>
						<td><%=rs("dept_name")%></td>
						<td><%=formatpercent(rs("tele_weight"),,-1)%></td>
						<%if CheckPostFlag(session("aaPostFlag"),2,15) then%>
						<td><a href="deltele.asp?tele_id=<%=rs("tele_id")%>">删除</a></td>
						<%end if%>
					</tr>
			<%
					rs.movenext
				loop
				rs.close
				set rs=nothing
			%>
				</tbody>
			</table>
		</div>
	</div>
</div>
<!--#include file="lib/footer.asp"-->
</body>
</html>
<!--#include file="lib/connclose.asp"-->

